<?php
namespace app\controllers\api\post;

use app\libs\LibUser;
use app\models\Posts;
use app\libs\RichContent;

// 获取我的
class GetmyController extends \fate\web\PureController {

    public function run() {
        // 是否登录
        $uid = LibUser::getLoginUid();
        if('' === $uid) {
            $this->ajaxReturn(null, 200001);
            exit;
        }

        $id = $_GET['id'];
        if(!is_numeric($id)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        $data = (new Posts())->getOne(
            'id,uid,cate_id,is_recommend,title,tags,thumb,brief,views,post_time,status,copyright',
            $id);

        if(null === $data) {
            $this->ajaxReturn(null, 400001);
            exit;
        }

        if($data['uid'] !== $uid) {
            $this->ajaxReturn(null, 200002);
            exit;
        }

        $data['content'] = (new RichContent())->protocolToHtml($data['content']);

        $this->ajaxReturn([
            'data' => $data
        ]);
    }

}
